package cn.net.sinodata.threadpool.base;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Description: 线程池工具栏
 *
 * @author: yinliangyun
 * @since: 2021-5-26
 */
public class ThreadPoolUtils {

	public static Date parseDateValue(Object obj, String formatString, Date defaultValue) {
		if ((obj instanceof Date)) {
			return (Date) obj;
		}
		if ((obj instanceof Calendar)) {
			return ((Calendar) obj).getTime();
		}
		if (obj != null) {
			SimpleDateFormat dateFormat = new SimpleDateFormat(formatString);
			try {
				return dateFormat.parse(obj.toString().trim());
			} catch (ParseException e) {
				return defaultValue;
			}
		}
		return defaultValue;
	}

	public static String formatDate(Date date, String pattern) {
		if (date == null) {
			return "";
		}
		SimpleDateFormat dateFormater = new SimpleDateFormat(pattern);
		return dateFormater.format(date);
	}

}
